﻿using Microsoft.AspNetCore.Mvc.TagHelpers;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using Xf.MvcTag.Enums;

namespace Xf.MvcTag
{
    /// <summary>
    /// https://docs.microsoft.com/zh-cn/aspnet/core/mvc/views/tag-helpers/authoring?view=aspnetcore-2.2
    /// </summary>
    public class ButtonTagHelper : TagHelper
    {
        /// <summary>
        /// 我喜欢直角btn-flat
        /// </summary>
        private const string btnDefault = "btn btn-flat ";
        //public string TestTo { get; set; }
        //public ModelExpression For { get; set; }
        [HtmlAttributeName("btn-type")]
        public BtnType BtnType { get; set; }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            string cl = btnDefault + EnumHelper.GetDisplay(BtnType);
            if (output.Attributes.TryGetAttribute("class", out TagHelperAttribute old))
                output.Attributes.SetAttribute("class", cl + " " + old.Value.ToString());
            else
                output.Attributes.SetAttribute("class", cl);
        }
    }
}
